package com.ruoyi.womp.service.impl;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.womp.mapper.SqlQueryMapper;
import com.ruoyi.womp.service.ISqlQueryService;

@Service
public class SqlQueryServiceImpl implements ISqlQueryService {

	@Autowired
	SqlQueryMapper sqlQueryMapper;

	public void executeSql(String sql) {
		sqlQueryMapper.executeSql(sql);
	}

	public Integer getInteger(String sql) {
		List<Map<String, Object>> list = sqlQueryMapper.queryMapList(sql);
		Iterator<String> keys = list.get(0).keySet().iterator();
		while (keys.hasNext()) {
			return Integer.parseInt(list.get(0).get(keys.next()).toString());
		}
		return 0;
	}

	public Map<String, Object> queryOne(String sql) {
		List<Map<String, Object>> list = sqlQueryMapper.queryMapList(sql);
		if (null != list && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}

	public List<Map<String, Object>> queryMapList(String sql) {
		return sqlQueryMapper.queryMapList(sql);
	}

	public Page<Map<String, Object>> queryPageMapList(Page<Map<String, Object>> page, String sql) {
		return page.setRecords(sqlQueryMapper.queryPageMapList(page, sql));
	}
}
